package iterate

import "github.com/duke-git/lancet/v2/maputil"

func MapReduceSlice[T any](slice []T, mapreduce func(item1 T, item2 T)) {
	for i, v1 := range slice {
		for j, v2 := range slice {
			if i < j {
				mapreduce(v1, v2)
			}
		}
	}
}

func MapReduceMap[K comparable, V any](srcMap map[K]V, mapreduce func(item1 V, item2 V)) {
	keys := maputil.Keys(srcMap)
	for i, k1 := range keys {
		for j, k2 := range keys {
			if i < j {
				mapreduce(srcMap[k1], srcMap[k2])
			}
		}
	}
}
